package com.ghck.server.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import com.ghck.server.dao.provider.MakerMapperProvider;
import com.ghck.server.model.Maker;

public interface MakerMapper {

	@Insert("insert into t_maker"
			+ "(user_id,contact_name,contact_phone,card_num,province,province_id,city,city_id,district,district_id,card_front,card_back,business_licence,status,create_time,last_modify_time)"
			+ "values"
			+ "(#{userId},#{contactName},#{contactPhone},#{cardNum},#{province},#{provinceId},#{city},#{cityId},#{district},#{districtId},#{cardFront},#{cardBack},#{businessLicence},#{status},#{createTime},#{lastModifyTime})")
	public Integer addMaker(Maker maker);
	
	@Update("update t_maker set status=#{status} where id=#{id}")
	public Integer updateMakerStatus(@Param("id")Integer id,@Param("status")Integer status);
	
	@Select("select * from t_maker where user_id=#{userId} order by last_modify_time desc limit 1 ")
	public Maker findMakerByUserId(@Param("userId")Integer userId);
	
	@Select("select * from t_maker where district_id=#{districtId} and status=1")
	public Maker findMakerByDistrictIdAndPass(Integer districtId);
	
	
	@Select("select * from t_maker where id=#{id}")
	public Maker findMakerById(@Param("id")Integer id);
	
	@SelectProvider(type=MakerMapperProvider.class,method="listMakers")
	public List<Maker> listMakers(@Param("maker")Maker maker, @Param("start")Integer start, @Param("limit")Integer limit);
	@SelectProvider(type=MakerMapperProvider.class,method="countListMakers")
	public Integer countListMakers(@Param("maker")Maker maker);
}
